/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package imp.reciever;

import dom.Command;
import dom.Reciever;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author julian.pena
 */
public abstract class ConcreteReciever implements Reciever{

    protected final static int BUFFER_SIZE = 1024*1024;
    protected final static String SEPARATOR = System.getProperty("file.separator");
    protected InputStream inputStream;
    protected OutputStream outputStream;
    protected Command command;
    protected boolean stop;
    protected String fileName;

    public ConcreteReciever(InputStream inputStream, OutputStream outputStream, Command command) {
        this.inputStream = inputStream;
        this.outputStream = outputStream;
        this.command = command;
        this.stop = false;
        this.fileName = "";
    }

    public ConcreteReciever(InputStream inputStream, OutputStream outputStream) {
        this.inputStream = inputStream;
        this.outputStream = outputStream;
        this.stop = false;
        this.fileName = "";
    }

    @Override
    public InputStream getInputStream() {
        return inputStream;
    }

    @Override
    public OutputStream getOutputStream() {
        return outputStream;
    }

    @Override
    public void setCommand(Command command) {
        this.command = command;
    }
    
    @Override
    public void notifyStop(String fileName){
        command.notifyStop(fileName);
    }
    
    @Override
    public void stop(String fileName){
        stop = true;
        this.fileName = fileName;
        while (stop) {         
            try {
                Thread.sleep(500L);
            } catch (InterruptedException ex) {
            }
        }
    }
}
